﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;

namespace DataLayer
{
    public static class DatCarga
    {
        public static bool cargarCredito(int idTarjeta, decimal monto, DateTime fecha)
        {
            List<Util.DBParameter> parameters = getListParameters(idTarjeta, monto, fecha);
            try
            {
                Util.SQLCommandBuild("RegistrarCarga", parameters).ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("error{0}", ex.Message);
                return false;
            }
        }

        private static List<Util.DBParameter> getListParameters(int idTarjeta, decimal monto, DateTime fecha)
        {
            List<Util.DBParameter> parameters = new List<Util.DBParameter>();

            Util.DBParameter myParam;
            myParam.dbType = System.Data.DbType.Int32;
            myParam.parameterName = "@IdTarjeta";
            myParam.value = idTarjeta;

            Util.DBParameter myParam1;
            myParam1.dbType = System.Data.DbType.Decimal;
            myParam1.parameterName = "@Monto";
            myParam1.value = monto;

            Util.DBParameter myParam2;
            myParam2.dbType = System.Data.DbType.DateTime;
            myParam2.parameterName = "@Fecha";
            myParam2.value = fecha;

            parameters.Add(myParam);
            parameters.Add(myParam1);
            parameters.Add(myParam2);

            return parameters;
        }
    }
}
